package com.ruoyi.review.service.impl;

import java.io.InputStream;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.review.domain.AReviewBatch;
import com.ruoyi.review.domain.ReviewUserLotVo;
import com.ruoyi.review.mapper.AReviewBatchMapper;
import com.ruoyi.review.service.IAReviewBatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-08
 */
@Service
public class AReviewBatchServiceImpl implements IAReviewBatchService
{
    @Autowired
    private AReviewBatchMapper aReviewBatchMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param batchId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public AReviewBatch selectAReviewBatchByBatchId(Long batchId)
    {
        return aReviewBatchMapper.selectAReviewBatchByBatchId(batchId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param aReviewBatch 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<AReviewBatch> selectAReviewBatchList(AReviewBatch aReviewBatch)
    {
        return aReviewBatchMapper.selectAReviewBatchList(aReviewBatch);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param aReviewBatch 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertAReviewBatch(AReviewBatch aReviewBatch)
    {

        return aReviewBatchMapper.insertAReviewBatch(aReviewBatch);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param aReviewBatch 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateAReviewBatch(AReviewBatch aReviewBatch)
    {
        return aReviewBatchMapper.updateAReviewBatch(aReviewBatch);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param batchIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAReviewBatchByBatchIds(Long[] batchIds)
    {
        return aReviewBatchMapper.deleteAReviewBatchByBatchIds(batchIds);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param batchId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteAReviewBatchByBatchId(Long batchId)
    {
        return aReviewBatchMapper.deleteAReviewBatchByBatchId(batchId);
    }

    @Override
    public void uploadDetail(InputStream in, Long id) {

    }

    @Override
    public List<ReviewUserLotVo> getList() {
        return aReviewBatchMapper.getlistDetails();
    }

    @Override
    public List<AReviewBatch> getReviewBatchList() {
        return aReviewBatchMapper.getList();
    }

    @Override
    public List<ReviewUserLotVo> getReviewUsers() {
        return aReviewBatchMapper.getUsers();
    }

    @Override
    public boolean saveReviewsAndBatchUser(ReviewUserLotVo vo) {
        if(vo == null) return false;
        int count = 0;
//        String[] split = null;
        if(StringUtils.isNotEmpty(vo.getBatchIds()) && vo.getUserId() != null){
//            split = vo.getBatchIds().split(",");
            for (int i = 0; i < vo.getBatchIds().length; i++) {
                count += (aReviewBatchMapper.saveReviewAndBatchUser(vo.getBatchIds()[i], vo.getUserId()));
            }
        }
        return vo.getBatchIds() == null ? false : vo.getBatchIds().length == count ? true : false;
    }
}
